package vim.meet.aspect;

import com.google.common.collect.Maps;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Map;

@Component
@Aspect
public class ProceedingJoinPointAspectAdvice {

    private Logger logger = LoggerFactory.getLogger(ProceedingJoinPointAspectAdvice.class);

    // 不需要同步用户数据的方法
    private static String[] methods = { "m1", "m2"};

    private static Map<String, Boolean> methodsMap = Maps.newHashMap();

    public ProceedingJoinPointAspectAdvice() {
        for (String key : methods) {
            methodsMap.put(key, true);
        }
    }

    @Around("execution(* cn.freemethod.service.impl.*.*(..))")
    public Object doAround(ProceedingJoinPoint jp) throws Throwable {
        MethodSignature joinPointObject = (MethodSignature) jp.getSignature();
        Method method = joinPointObject.getMethod();
        String methodName = method.getName();
//        Object[] args = jp.getArgs();
        if (methodsMap.get(methodName) == null) {
            boolean flag = false;
            if (methodName.equals("findListIndexActivities")
                    || methodName.equals("listIndexActivities")) {
                
            } else {
                
            }
            if (!flag) {
                logger.error("method name:" + methodName);
                return null;
            }
        }
        return jp.proceed();
    }
}